﻿using System.Collections.Generic;
using System.Linq;
using DomenModel;
using Model.Repositories.Interfaces;
using System.Data.Entity;

namespace OmsTestProject.MockRepository
{
    public class StatusRepository : ICrud<Status>
    {
        MockRepositoryContext _db = MockRepositoryContext.MockContextInstance;

        public Status GetById(long Id)
        {
                Status statusById = _db.Statuses.FirstOrDefault(p => p.StatusId == Id);
                return statusById;
        }

        public Status GetByTitle(string Name)
        {
                Status statusByTitle = _db.Statuses.FirstOrDefault(p => p.Title == Name);
                return statusByTitle;
        }

        
          public void Save(Status status)
          {
                  _db.Statuses.Add(new Status
                  {

                      Title = status.Title,
                      Value = status.Value,
                      Discount = status.Discount,

                  });
          }

          public void Update(Status status)
          {
                  _db.Statuses[status.StatusId].Title = status.Title;
                  _db.Statuses[status.StatusId].Value = status.Value;
                  _db.Statuses[status.StatusId].Discount = status.Discount;
          }

          public void Delete(long Id)
          {
                  Status statusById = _db.Statuses.First(p => p.StatusId == Id);
                  _db.Statuses.Remove(statusById);
          }   

        public List<Status> GetCollection()
        {
                return _db.Statuses;
        } 
    }
}
